$.fn.sanshi_upload=function(max_length,up_name,show_msg){
	var file_class_name = "";
	var span_class_name ="";
	//取得当前加载的div的id
	var div_id = $(this).attr('id');
	//定义上传的文件类型
	this.allowFile = $.fn.sanshi_upload.allowFile();
	//定义产生的标签
	var make_input_tag = function(name,class_name)
	{
		var obj = $(document.createElement(('INPUT')));
		obj.attr('type','file');
		obj.attr('name',name);
		obj.attr('id',name);
		var dr = new Date().getTime();
		//alert(Math.random()*dr);
		obj.attr('lid',Math.random()*dr);
		obj.attr('class',file_class_name);
		return obj;
	}
	var add_show_msg=function(bug_msg,file_obj)
	{
		var object = $('#'+show_msg);
		var div_obj = $(document.createElement(('DIV')));
		div_obj.attr('lid',file_obj.attr('lid'));
		div_obj.click(function(){
			//取得唯一id
			var one_no = $(this).attr('lid');
			//删除显示列表
			$("#"+show_msg+" > div[lid="+one_no+"]").remove();
			$("#"+div_id+" > input[type='file'][lid="+one_no+"]").remove();
		});
		div_obj.append(bug_msg+" "+'删除');
		object.append(div_obj);
	}
	var del_fuc = function(obj){
		alert('asdf');
	}
	var add_file_fuc = function(file_object,div_object)
	{
			//如果文件为空
			if(file_object.val()=="") return false;
			//文件类型
			if(!$.fn.sanshi_upload.check_file_type(file_object.val())) return false;
			//检查是否超过数量
			if($("#"+div_id+" > input[type='file']").size() >= max_length)
			{
				alert("最多只能上传"+max_length+"个附件");
				return false;
			}
			//删除标签单击事件
			add_show_msg("文件名："+file_object.val(),file_object);
			//当前的隐藏
			file_object.hide();
			//增加一个新的文件上传框
			div_object.append(add_file(div_object));
	}
	var add_file = function(div_object){
		var file_object = make_input_tag(up_name,file_class_name);
		file_object.bind('change',function(){add_file_fuc(file_object,div_object);});
		return file_object;
	}
	var init = function(){
		var div_object = $('#'+div_id);
		div_object.append(add_file(div_object));		
	}
	init();
}
$.fn.sanshi_upload.allowFile = function(){	return Array('txt','jpg','jpeg','bmp','png','rar','zip','doc','xls','ppt','pdf','vsd','wps','et','dps')};
$.fn.sanshi_upload.check_file_type =function(file_name){
	var file_type = file_name.substring(file_name.lastIndexOf('.')+1, file_name.length);
	var lock =false;
	var allowFile = $.fn.sanshi_upload.allowFile();
	for(key in allowFile) 
	{
		if(allowFile[key] ==file_type) lock=true;
	}
	if(!lock) alert("该类型文件不允许上传");
	return lock;
}